<%-- 
    Document   : Employee_Details
    Created on : Apr 7, 2015, 10:29:50 PM
    Author     : user
--%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="com.uniq.db.ConnectionFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
      <%@include file="AdminHeader.jsp"%>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript">
            function submitSource()
            {
                var source=document.getElementById("source").value;
                alert('selected source is '+source);
                document.forms['stock_exchange'].submit();
            }
            
            function exchange()
            {
                alert('submit');
                document.forms['stock_exchange'].action="./AddDefects";
                 document.forms['stock_exchange'].submit();
            }
        </script>
        
    </head>
    <body>
        <form name="stock_exchange" >
        Select a user role to view details :
        <select name="source" action="Exchange" onchange=" submitSource()" id="source">
            <%     String source=request.getParameter("source");
            if(source==null)
        {
    %>
    
       <option>Select Role</option>
          <option value="user">Users</option>
          <option value="employee">Employees</option>
      
            <%
            }
   
                      else if(source.equalsIgnoreCase("user"))
        {
              %>
       <option>Select Role</option>
          <option value="user" selected="">Users </option>
          <option value="employee"> Employees </option>
            <%
            }
     
                      else if(source.equalsIgnoreCase("employee"))
        {
              %>
          <option>Select Role</option>
          <option value="user">Users</option>
          <option value="employee" selected="">Employees</option>
          
            <%
            }
    %>
      </select>
<%

if(source!=null)        
        {
    Connection con=ConnectionFactory.getConnection();
    Statement st=con.createStatement();
    
    ResultSet rs=st.executeQuery("SELECT * from login where role='"+source+"'");
    out.println("<ul class='news_list'>");
    out.println("<table style='width:100%'>");
    int c=0;
     out.println("<th>S no</th>");
     out.println("<th>First Name</th>");
     out.println("<th>Last Name</th>");
     out.println("<th>User Name</th>");
     out.println("<th>Password</th>");
     out.println("<th>Role</th>");
       while(rs.next())
    {
        c++;
       out.println("<tr>");
       out.println("<td align='center'>"+c+"</td>"); 
       out.println("<td align='center'>"+ rs.getString("firstname") +"</td>"); 
       out.println("<td align='center'>"+rs.getString("lastName")+"</td>"); 
       out.println("<td align='center'>"+rs.getString("userName")+"</td>"); 
       out.println("<td align='center'>"+rs.getString("password")+"</td>"); 
       out.println("<td align='center'>"+rs.getString("role")+"</td>"); 
 
       out.println("</tr>");
        
    }
     out.println("<table'>");

   


        }


%>
      </form>

    </body>
</html>

